<?php
$getPackagePrice = Yii::$app->params['getPackagePrice']; //价格
$getCateGory     = Yii::$app->params['projectCategory1']; //类别
$getPakcageState = Yii::$app->params['projectState']; //状态
$getPackageType = Yii::$app->params['isSuit']; //诉讼状态
$industrys = Yii::$app->params['industrys']; //所属行业
$mortgageType =  Yii::$app->params['mortgageTypes3']; //抵押物
$provinceData = $provinceData; //省
?>
<!-- 本金数额 -->
<div class="clearfix options-content-form">
    <a href="/search-all/?postion=3&keyWords=" style="color: #2194f1;float: right;font-size: 14px;margin-right: 100px;">清除查询条件</a>
</div>
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">本金数额</label>
    <?php
    $principal = Yii::$app->request->get('principal',0);
    foreach ($getPackagePrice as $k => $v){
        $priceName  = $v['name'];
        if ($k == $principal){
            echo <<<PRICE
    <span class='active priceProjectSearch' data-val="$k">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='priceProjectSearch' data-val="$k">$priceName</span>
PRICE;
        }

    }
    ?>
</div>

<!-- 2.当前状态 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">当前状态</label>
    <?php
    $dangqianzhuangtai =  Yii::$app->request->get('packageState',0);
    foreach ($getPakcageState as $k => $v){
        $priceName  = $v['name'];
        $val = $v['val'];
        if ($v['val'] == $dangqianzhuangtai){
            echo <<<PRICE
    <span class='active stateProjectSearch' data-val="$val">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='stateProjectSearch' data-val="$val">$priceName</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 3.资产包类别 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">项目类别</label>
    <?php
    $category = Yii::$app->request->get('category',0);
    foreach ($getCateGory as $k => $v){
        $priceName  = $v['name'];
        if ($k == $category){
            echo <<<PRICE
    <span class='active cateProjectSearch' data-val="$k">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='cateProjectSearch' data-val="$k">$priceName</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 4.诉讼状态 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">诉讼状态</label>
    <?php
    $zichanleixing = Yii::$app->request->get('packageType',-2);
    if ($zichanleixing==""){
        $zichanleixing = -2;
    }
    foreach ($getPackageType as $k => $v){
        $priceName  = $v['name'];
        if ($k == $zichanleixing){
            echo <<<PRICE
    <span class='active typeProjectSearch' data-val="$k">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='typeProjectSearch' data-val="$k">$priceName</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 5.抵押物类型 -->
<div class="clearfix options-content-form options-content-form2"  id="diyawuTag">
    <label for="" class="pull-left control-label">抵押物类型</label>
    <?php

    $diyawu = array_filter(explode(",",Yii::$app->request->get("diyawu",",")));
    if (!empty($diyawu)){
        echo '<span class="diyawuSearchAll" data-val="0">全部</span>';
    }else{
        echo '<span class="diyawuSearchAll active" data-val="0">全部</span>';
    }
    foreach ($mortgageType as $k => $v) {
        $name = $v['name'];
        $val = $v['val'];
        if (in_array($val, $diyawu)) {
            echo <<<PRICE
            <span class="diyawuSearch active" data-val="$val">$name</span>
PRICE;
        } else {
            echo <<<PRICE
            <span class="diyawuSearch" data-val="$val">$name</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 5.省份地区 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">省份地区</label>
    <div class="options-content-form-list pull-right">
        <?php
        $province = Yii::$app->request->get('province',0);
        if (!empty($provinceData) && is_array($provinceData)){
            foreach ($provinceData as $k => $v){
                $title  = $v['title'];
                $id = $v['id'];
                if ($id == 3553 && $province == 0){
                    echo <<<PRICE
            <span class='active province ' data-val="0">$title</span>
PRICE;
                }elseif ($id == 3553){
                    echo <<<PRICE1
            <span class='province ' data-val="0">$title</span>
PRICE1;
                }
            }
            foreach ($provinceData as $k => $v){
                $title  = $v['title'];
                $id = $v['id'];
                if ($id!=3553 && $id == $province){
                    echo <<<PRICE
            <span class='active province' data-val="$id">$title</span>
PRICE;
                }else if ($id!=3553){
                    echo <<<PRICE
            <span class='province' data-val="$id">$title</span>
PRICE;
                }
            }
        }
        ?>
    </div>
    <div class="options-content-form-list2 pull-right" id="city">
    </div>

</div>
<!--6. 行业分类 -->
<div class="clearfix options-content-form options-content-form2" id="industrysTag">
    <label for="" class="pull-left control-label mb40">行业分类</label>
    <?php
    $industry = array_filter(explode(",",Yii::$app->request->get("industry",",")));
    if (!empty($industry)){
        echo '<span class="industrysProjectSearchAll" data-val="0">全部</span>';
    }else{
        echo '<span class="industrysProjectSearchAll active" data-val="0">全部</span>';
    }
    foreach ($industrys as $k => $v){
        $name  = $v['name'];
        $val = $v['val'];
        if (in_array($val,$industry)){
            echo <<<PRICE
            <span class="industrysProjectSearch active" data-val="$val">$name</span>
PRICE;
        }else{
            echo <<<PRICE
            <span class="industrysProjectSearch" data-val="$val">$name</span>
PRICE;
        }

    }
    ?>
</div>

<script>
    $(function () {
        //--------------start-----------fly----------------------
        //点击省份加载城市
        $(".province").click(function () {
            city = 0;
            var provinceId = $(this).data('val');
            province = provinceId;
            $.get('/search-package/ajax-city',{'provinceID':provinceId},function (res) {
                var resData = JSON.parse( res );
                if (resData.code==200){
                    readringCity(resData.data.res);
                    var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&entry=sala&postion=3';
                    window.location.href = url;
                }else{
                    layer.msg("错误")
                }
            })
        })
        //刷新页面加载城市数据
        getProvinceID = '<?= $province ?>';
        $().ready(function(){
            if (getProvinceID != 0){
                $.get('/search-package/ajax-city',{'provinceID':getProvinceID},function (res) {
                    var resData = JSON.parse( res );
                    if (resData.code==200){
                        readringCity(resData.data.res);
                    }else{
                        layer.msg("错误")
                    }
                })
            }else{
                $("#city").hide();
            }
        })
        //渲染城市
        function readringCity(resData) {
            cityId = '<?=Yii::$app->request->get("city",0)?>';
            var cityHtml = "";
            if (cityId == 0){
                cityHtml = "<span class='active cityProjectSearch' data-val='0'>全部</span>";
            }else{
                cityHtml = "<span class='cityProjectSearch' data-val='0'>全部</span>";
            }
            $(resData).each(function(i,e){
                var title = e.title;
                var id    = e.id;
                if (cityId == id){
                    cityHtml+= "<span class='active cityProjectSearch'  data-val='"+id+"'>"+title+"</span>";
                }else{
                    cityHtml+= "<span class='cityProjectSearch'  data-val='"+id+"'>"+title+"</span>";
                }
            });
            $("#city").html("");
            $("#city").append(cityHtml);
        }
        //组织条件搜索
        //价格
        $(".priceProjectSearch").click(function () {
            principal = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //类别
        $(".cateProjectSearch").click(function () {
            zichanbaobei = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //状态
        $(".stateProjectSearch").click(function () {
            dangqianzhuangtai = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //诉讼状态
        $(".typeProjectSearch").click(function () {
            zichanleixing = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //城市
        $(document).on('click','.cityProjectSearch',function () {
            city = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //抵押物
        $(".diyawuSearch").click(function () {
            //判断是否选中，如果选中则取消
            if ($(this).hasClass("active")){
                $(this).removeClass("active");
            }else{
                $(this).addClass("active");
            }
            diyawu = ',';
            $("#diyawuTag span").each(function(){
                var diyawuClass = $(this).attr('class');
                if (diyawuClass == 'diyawuSearch active'){
                    diyawu = diyawu+$(this).data('val')+',';
                }
            });
            if (diyawu == ','){
                diyawu = '';
            }
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        $(".diyawuSearchAll").click(function () {
            //判断是否选中，如果选中则取消
            diyawu = 0;
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //行业分类
        $(".industrysProjectSearch").click(function () {
            //判断是否选中，如果选中则取消
            if ($(this).hasClass("active")){
                $(this).removeClass("active");
            }else{
                $(this).addClass("active");
            }
            industry = ',';
            $("#industrysTag span").each(function(){
                var industrysClass = $(this).attr('class');
                if (industrysClass == 'industrysProjectSearch active'){
                    industry = industry+$(this).data('val')+',';
                }
            });
            if (industry == ','){
                industry = '';
            }
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        $(".industrysProjectSearchAll").click(function () {
            industry = 0;
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&diyawu='+diyawu+'&order='+orderP+'&entry=sala&postion=3';
            window.location.href = url;
        })
        //--------------end-----------fly----------------------
    })
</script>